﻿using BCCommon.Enums.Driver;
using BCCommon.TMS.Driver;
using BCDto.Common.ErrorMessage;
using BCDto.TMS.Driver;
using BCDto.TMS.Driver.VehicleBusiness;
using BCService.SmsService;
using BCService.TMS.Driver;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Mvc;
using System;

namespace BCTMSRESTful.Controllers.DriverApp.Driver
{
    /// <summary>
    /// 司机端司机接口信息
    /// </summary>
    [ApiExplorerSettings(GroupName = "DriverApp")]
    [Route("api/v1/DriverApp/[controller]")]
    public class DriversController : DriverAppBaseController
    {
        private readonly TimeSpan expiration = TimeSpan.FromDays(1);
        private readonly IDriverService driverService;
        private readonly IAliyunSmsService aliyunSmsService;

        public DriversController(IDriverService driverService, IAliyunSmsService aliyunSmsService)
        {
            this.driverService = driverService;
            this.aliyunSmsService = aliyunSmsService;
        }

        /// <summary>
        /// 获取当前登录的司机。
        /// </summary>
        /// <returns></returns>
        /// <response code="200">用户信息。</response>
        /// <response code="204">无法找到指定的用户。</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        /// <response code="500">服务器内部错误。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(DriverDto), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult Current()
        {
            return this.Ok(this.Driver);
        }

        #region 实名认证
        /// <summary>
        /// 实名认证
        /// </summary>
        /// <param name="dto">实名认证信息</param>
        /// <returns></returns>
        /// <response code="200">实名认证信息提交成功。</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        /// <response code="500">服务器内部错误。</response>
        [HttpPost("[action]")]
        [Log("司机实名认证")]
        [ProducesResponseType(typeof(DriverDto), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult RealNameVerifies([FromBody] RealNameVerifiesRequestDto dto)
        {
            var driver = this.driverService.RealNameVerifies(this.Driver.DriverId, dto);
            return Ok(driver);
        }
        #endregion

        #region 人脸识别
        /// <summary>
        /// 人脸识别认证
        /// </summary>
        /// <param name="dto">人脸识别认证信息</param>
        /// <returns></returns>
        /// <response code="200">人脸识别认证信息提交成功。</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        /// <response code="500">服务器内部错误。</response>
        [HttpPost("[action]")]
        [Log("司机人脸识别认证")]
        [ProducesResponseType(typeof(DriverDto), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult FaceVerifies([FromBody] FaceVerifiesRequestDto dto)
        {
            var driver = this.driverService.FaceVerifies(this.Driver.DriverId, dto);
            return Ok(driver);
        }
        #endregion

        #region 车辆信息
        /// <summary>
        /// 上传机动车辆信息
        /// </summary>
        /// <param name="dto">机动车辆信息</param>
        /// <response code="200">上传机动车辆信息提交成功。</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        /// <response code="500">服务器内部错误。</response>
        /// <returns></returns>
        [HttpPost("[action]")]
        [Log("上传机动车辆信息")]
        [ProducesResponseType(typeof(DriverDto), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult UploadVehicle([FromBody] VehicleRequestDto dto)
        {
            var driver = this.driverService.UploadVehicle(this.Driver.DriverId, dto);
            return Ok(driver);
        }


        #endregion

        #region 城市信息
        /// <summary>
        /// 切换城市
        /// </summary>
        /// <param name="dto">切换城市信息</param>
        /// <returns></returns>
        /// <response code="200">切换城市信息成功。</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        /// <response code="500">服务器内部错误。</response>
        [HttpPost("[action]")]
        [Log("切换城市信息")]
        [ProducesResponseType(typeof(DriverDto), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult ChangeCity([FromBody] ChangeCityRequestDto dto)
        {
            var driver = this.driverService.ChangeCity(this.Driver.DriverId, dto);
            return Ok(driver);
        }
        #endregion

        #region 切换工作状态
        /// <summary>
        /// 切换工作状态
        /// </summary>
        /// <param name="workingStatus">当前司机工作状态</param>
        /// <returns></returns>
        /// <response code="200">切换工作状态成功。</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        /// <response code="500">服务器内部错误。</response>
        [HttpPut("[action]/{working_status}")]
        [Log("切换工作状态")]
        [ProducesResponseType(typeof(DriverDto), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult ChangeWorkingStatus([FromRoute(Name = "working_status")] DriverWorkingStatusForApp workingStatus)
        {
            if (this.Driver.WorkingStatus == DriverWorkingStatus.Stopped)
            {
                throw new ArgumentException("司机已被停运，不能操作。");
            }
            var driver = this.driverService.ChangeWorkingStatus(this.Driver.DriverId, workingStatus);
            return Ok(driver);
        }
        #endregion


    }
}
